package com.happy016.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfig {

    /**
     * 创建 一个名为 hello队列
     * @author Linyb
     * @since 2017/11/20 11:22
     */
    @Bean
    public Queue hello(){
        return new Queue("hello");
    }

    @Bean
    public Queue topic(){
        return new Queue("test");
    }


    final static String message = "topic.message";
    final static String messages = "topic.messages";

    @Bean
    public Queue queueMessage() {
        return new Queue(RabbitmqConfig.message);
    }

    @Bean
    public Queue queueMessages() {
        return new Queue(RabbitmqConfig.messages);
    }

    @Bean
    TopicExchange exchange() {
        return new TopicExchange("exchange");
    }

    /**
     * topic.message 使用 topic.message topic.messages匹配
     * @author Linyb
     * @since 2017/11/22 16:20
     */
    @Bean
    Binding bindingExchangeMessage(Queue queueMessage, TopicExchange exchange) {
        return BindingBuilder.bind(queueMessage).to(exchange).with("topic.message");
    }

    /**
     * topic.# 使用topic.messages匹配
     * @author Linyb
     * @since 2017/11/22 16:19
     */
    @Bean
    Binding bindingExchangeMessages(Queue queueMessages, TopicExchange exchange) {
        return BindingBuilder.bind(queueMessages).to(exchange).with("topic.#");
    }
}
